#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
Inserts output headers into <div id="output-headers" />.
This may be useful for debugging.
"""

import xml.dom.minidom
import time

# TODO: parameter 'highlight'

def execute_minidom(server, document, parameters):
	for n in document.getElementsByTagName('div'):
		if n.hasAttribute('id') and n.getAttribute('id') == 'output-headers':
			# Build string
			headers = []
			for h in server.headers:
				headers.append('%s: %s\n' % (h, server.headers[h]))
			headers = ''.join(headers)

			# Insert
			div = document.createElement('pre')
			div.appendChild(document.createTextNode(headers))
			n.appendChild(div)
